package com.xiaour.spring.boot;


import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;

@GrpcService
public class UserServiceImpl extends UserServiceGrpc.UserServiceImplBase {

    @Override
    public void getUser(UserProto.UserRequest request, StreamObserver<UserProto.UserResponse> responseObserver) {
        UserProto.UserResponse response = UserProto.UserResponse.newBuilder()
                .setId(request.getId())
                .setName("John Doe")
                .setEmail("john.doe@example.com")
                .build();

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }

    public static void main(String[] args) throws Exception {
        Server server = ServerBuilder.forPort(50051)
                .addService(new UserServiceImpl())
                .build()
                .start();

        System.out.println("Server started, listening on " + server.getPort());

        server.awaitTermination();
    }
}
/*
@GrpcService
public class UserServiceImpl extends UserServiceGrpc.UserServiceImplBase {

    @Override
    public void getUser(UserRequest request, StreamObserver<UserResponse> responseObserver) {
        UserResponse response = UserResponse.newBuilder()
            .setId(request.getId())
            .setName("John Doe")
            .setEmail("john.doe@example.com")
            .build();

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}*/